package com.turbo.cloud.rule.cmp.age;

import com.turbo.cloud.core.exception.BusinessException;
import com.yomahub.liteflow.annotation.LiteflowComponent;
import com.yomahub.liteflow.core.NodeComponent;
import com.yomahub.liteflow.core.NodeIfComponent;
import lombok.extern.slf4j.Slf4j;

import java.util.Map;
import java.util.Objects;

/**
 * @author zhangluning
 * Liteflow 编排规则18-55岁
 */
@Slf4j
@LiteflowComponent("Age18_55Rule")
public class Age18_55RuleCmp extends NodeIfComponent {

    /**
     * 最小限制年龄
     */
    final static Integer MIN_AGE = 18;
    /**
     * 最大限制年龄
     */
    final static Integer MAX_AGE = 55;

    @Override
    public boolean processIf() {
        try {
            Integer age = (int) ((Map) getRequestData()).get("age");
            if (age >= MIN_AGE && age <= MAX_AGE) {
                return true;
            }
            throw new BusinessException("年龄不在18-55岁之间");
        } catch (Exception e) {
            log.error("Liteflow 编排规则18-55岁异常", e);
            throw new BusinessException(e.getMessage());
        }
    }
}
